var geocoder, map, res

function initialize() {
   var latlng = new google.maps.LatLng(-34.397, 150.644);
   var myOptions = {
     zoom: 8,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   
   map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
   res = document.getElementById("geo_results");
   geocoder = new google.maps.Geocoder();
}

function search_submit() {
   var query = $("#id_query").val();
   var address = $("#id_location").val();
   geocoder.geocode( { 'address': address }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
	     map.setCenter(results[0].geometry.location);
		 var marker = new google.maps.Marker({
			map: map,
			position: results[0].geometry.location
		 });
		 $('#geo_results').text(function(index) { return 'ya:' + results[0].geometry.location.ya +
             ' za: ' + results[0].geometry.location.za; });
		 res.write('test');
	  } else {
	     alert("Geocode was not successful for the following reason: " + status);
	  }
   });

   //$("#search-results").load("/search/?ajax&query=" + encodeURIComponent(query));
   return false;
}


$(document).ready(function () {
	initialize();
   $("#search-form").submit(search_submit);
});
